﻿

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vw_medianamik_NodeRevision]'))
BEGIN
	declare @sql nvarchar(4000)
	SET @sql = 'ALTER VIEW [dbo].[vw_medianamik_NodeRevision]
AS
SELECT	nr.*
FROM	medianamik_NodeRevision nr
		left join dbo.medianamik_NodeRevision latest  on nr.NodeId = latest.NodeId and nr.CreatedOn > latest.CreatedOn
WHERE	nr.PublishedOn is null 
and		latest.NodeId is null'
						  
	exec sp_executesql @sql

END

